<template>
	<u-popup border-radius="20" v-model="value" mode="center" :closeable="false" @close="$emit('input',false)">
		<view class="container">

			<view class="title">
				设备信息
			</view>
			<view class="device">
				{{content.equipment}}
			</view>
			<view class="content">
				<text class="label">位置</text>
				<text class="value">{{content.equipmentAddress}}</text>
			</view>
			<view class="repair">
				<HButton @click="onRepair">设备报修</HButton>
			</view>
			<view class="rescanCode">
				<text @click="onRescanCode">重新扫码</text>
			</view>
		</view>
	</u-popup>
</template>

<script>
	import {
		getScanCodeContent
	} from '../../apis/report'
	import HButton from '../button/index.vue'
	import PagesIndexRouterConfig from '@/pages/index/routerConfig.js'
	export default {
		model: {
			// 处理 v-model 失效的问题
			prop: "value",
			event: "input"
		},
		props: {
			value: {
				type: Boolean,
				default: false
			},
			code: {
				type: String,

				default: ''
			}
		},
		data() {
			return {
				content: {
					equipment: "",
					equipmentAddressId: null,
					equipmentAddress: "",
					acceptDeptName: null,
					acceptDeptId: null,
				}
			}
		},
		components: {
			HButton
		},
		mounted() {

		},
		methods: {
			async getScanData(code, isRescan) {
				const res = await getScanCodeContent(this.code || code)
				const {
					body
				} = res
				this.content = body
				this.$emit('input', true)

			},
			scanCode() { 
				const self = this
				uni.scanCode({
					onlyFromCamera: true,
					hideAlbum: true,
					success: function(res) { 
						console.log(res,'res');
						
							if(res.scanType ==='WX_CODE'){
								// 科室码
								const query = res.path.split('?')
								const url = `${PagesIndexRouterConfig.report}?${query[1]}`
							wx.navigateTo({
								url,
								fail(err){
									console.log(err,'err')
								}
							})
							}else{
								
							self.getScanData(res.result)
							}
					 

					}, 
				})
			},
			// 重新扫码
			onRescanCode() {
				this.$emit('input', false)
				this.scanCode()

			},
			// 设备报修
			onRepair() {
				const self = this
				const query = this.$u.queryParams({
					type: 'scan',
					value: this.code,
					...this.content
				})
				const url = `${PagesIndexRouterConfig.report}${query}`
				wx.navigateTo({
					url,
					success() {
						self.$emit('input', false)
					},
					fail(err) {
						console.log(err, 'err');
					}
				})
			},
		 
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 510rpx;
		padding: 30rpx;
	}

	.title {
		font-weight: 400;
		font-size: 32rpx;
		color: #0F2E4D;
		text-align: center;
	}

	.device {
		margin-top: 60rpx;
		font-weight: 600;
		font-size: 36rpx;
		color: #0F2E4D;

	}

	.content {
		margin-top: 30rpx;

		>.label {
			font-weight: 400;
			font-size: 28rpx;
			color: #98A5B3;
		}

		>.value {
			font-weight: 400;
			font-size: 28rpx;
			color: #0F2E4D;
			margin-left: 20rpx;
		}
	}

	.repair {
		text-align: center;
		margin-top: 60rpx;
	}

	.rescanCode {
		margin-top: 40rpx;
		font-weight: 400;
		font-size: 28rpx;
		color: #409EFF;
		text-align: center;
	}
</style>
